package com.css.fxfzypg.modules.baseData.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.css.fxfzypg.constants.YNEnum;
import com.css.fxfzypg.modules.baseData.entity.ErcmEntity;
import com.css.fxfzypg.modules.baseData.queryParams.ErcmQueryParams;
import com.css.fxfzypg.modules.baseData.repository.ErcmRepository;
import com.css.fxfzypg.modules.baseData.service.ErcmService;
import com.css.fxfzypg.util.PlatformDateUtils;
import com.css.fxfzypg.util.PlatformPageUtils;
import com.css.fxfzypg.util.UUIDGenerator;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.sql.Timestamp;
import java.util.List;
import java.util.Map;

/**
 * @author y1fan
 * @create 2022-08-29 16:35
 */
@Service
public class ErcmServiceImpl implements ErcmService {

    @Resource
    private ErcmRepository ercmRepository;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public ErcmEntity saveErcm(ErcmEntity ercmEntity) {
        ercmEntity.setErcmId(UUIDGenerator.getUUID());
        ercmEntity.setErcmCreatetime(PlatformDateUtils.getCurrentTimestamp());
        ercmEntity.setErcmIsdelete(YNEnum.Y.toString());
        return ercmRepository.saveErcm(ercmEntity);
    }

    @Override
    public Object getErcmById(String id) {

        return ercmRepository.getErcmById(id);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public ErcmEntity updateErcm(ErcmEntity ercmEntity) {
        ercmEntity.setErcmUpdatetime(PlatformDateUtils.getCurrentTimestamp());
        return ercmRepository.updateErcm(ercmEntity);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void deleteErcm(List<String> ids) {
        Timestamp currentTimestamp = PlatformDateUtils.getCurrentTimestamp();
        ercmRepository.deleteErcm(ids,currentTimestamp);
    }

    @Override
    public Map<String,Object> getAllErcmByParams(ErcmQueryParams queryParams) {
        return ercmRepository.getAllErcmByParams(queryParams);

    }
}
